package com.wangzhy.common.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author ：wangzy
 * @date ：  2021/8/18 11:52
 * @description： 返回对象
 */
@ApiModel("返回对象")
public class Result<T>  {

    @ApiModelProperty("状态")
    private int status = 1;

    @ApiModelProperty("返回消息")
    private String msg = "操作成功";

    @ApiModelProperty("返回数据")
    private T data;

    public Result(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public Result(int status, String msg, T data) {
        this.data = data;
        this.status = status;
        this.msg = msg;
    }

    public static <T> Result<T> success() {
        return new Result<T>(1, "操作成功");
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(1, "操作成功", data);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<T>(1, msg);
    }

    public static <T> Result<T> faild() {
        return new Result<T>(0, "操作失败");
    }

    public static <T> Result<T> faild(String msg) {
        return new Result<T>(0, msg);
    }

    public static <T> Result<T> faild(T data) {
        return new Result<T>(0, "操作失败", data);
    }

    public int getStatus() {
        return this.status;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
}
